/*************************************************************************
 * File Name:    maxflow.cc
 * Author:       zero91
 * Mail:         jianzhang9102@gmail.com
 * Created Time: Sun 20 Oct 2013 03:29:58 PM CST
 * 
 * Description:  max flow template, contains:
 *               1. Edmonds–Karp algorithm
 ************************************************************************/

 class max_flow_t {
 public:
 };

#define MAXDW 55
#define MATRIX_ROW (MAXDW * 3)

#ifdef INFINITY
#undef INFINITY
#endif
#define INFINITY 0x7FFFFFFF

int cap[MATRIX_ROW][MATRIX_ROW];

int
bfs(int src, int target, int *pre)
{
    queue<int> Q;
    int v;
    bool visited[target + 1];
    int flow[target + 1];

    memset(visited, false, sizeof(visited));
    visited[src] = true;
    for (int i = 0; i <= target; ++i) flow[i] = INFINITY;

    pre[src] = src;
    Q.push(src);
    while (!Q.empty()) {
        v = Q.front(), Q.pop();
        if (v == target) break;
        for (int i = 0; i <= target; ++i) {
            if (cap[v][i] == 0 || visited[i]) continue;
            visited[i] = true;
            pre[i] = v;
            flow[i] = min(flow[v], cap[v][i]);
            Q.push(i);
        }
    }
    if (flow[target] == INFINITY) return 0;
    return flow[target];
}

int
maxflow(int src, int target)
{
    int sum = 0;
    int aug, t;
    int pre[target + 1];
    while ((aug = bfs(src, target, pre)) > 0) {
        sum += aug;
        t = target;
        while (pre[t] != t) {
            cap[pre[t]][t] -= aug;
            cap[t][pre[t]] += aug;
            t = pre[t];
        }
    }
    return sum;
}

int
main(int argc, char *argv[])
{
    std::ios_base::sync_with_stdio(false);

    int T, N;
    int d, w, total_cost_day;
    int src, target;
    int week[8];

    scanf("%d", &T);
    for (int k = 1; k <= T; ++k) {
        memset(cap, 0, sizeof(cap));
        scanf("%d", &N);

        src = 0, target = N + 8;
        total_cost_day = 0;
        for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= 7; ++j) scanf("%d", &week[j]);
            scanf("%d %d", &d, &w);
            for (int j = 1; j <= 7; ++j) {
                if (week[j] == 0) continue;
                if (cap[src][j] < w) cap[src][j] = w;
                cap[j][i + 7] = w;
            }
            total_cost_day += d;
            cap[i + 7][target] = d;
        }
        if (maxflow(src, target) == total_cost_day) {
            printf("Yes\n");
        } else {
            printf("No\n");
        }
    }
    return 0;
}
